package cn.edu.swufe.stu2025.myapplication;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        TextView result,suggest;
        result=findViewById(R.id.res);
        suggest=findViewById(R.id.suggest);

        EditText hight=findViewById(R.id.hight);
        EditText weight=findViewById(R.id.weight);

        Button b=findViewById(R.id.btn);
        String qing="增加营养摄入，选择富含蛋白质、健康脂肪和碳水化合物的食物。适度力量训练有助于增肌";
        String zheng="保持均衡饮食和规律运动，继续健康的生活方式";
        String zhong="调整饮食，减少高热量食物，增加蔬果和全谷物摄入。结合有氧运动和力量训练来控制体重";
        String fei="制定减重计划，减少高糖高脂食物，增加运动量。必要时寻求专业帮助。";

        b.setOnClickListener(v -> {
            double h,w;
            try {
                h = Double.parseDouble(hight.getText().toString());
                h = h / 100;
                w = Double.parseDouble(weight.getText().toString());
                double bmi = w / (h * h);
                result.setText("你的BMI指数是：" + String.format("%.2f", bmi));
                if (bmi < 18.5) suggest.setText(qing);
                else if (bmi < 24.9) suggest.setText(zheng);
                else if (bmi < 29.9) suggest.setText(zhong);
                else suggest.setText(fei);
            }
            catch(Exception e){
                result.setText("请检查输入是否为空");
            }
        });

    }
}